<template>
  <div>
    <el-table :data="items">
      <el-table-column label="ID" prop="id"></el-table-column>

      <!-- <el-table-column label="" prop="name"></el-table-column> -->

      <el-table-column label="域名">
        <template #default="scope">
          <el-button
            type="primary"
            link
            :title="getHomePageURL(scope.row)"
            @click="handleClickWebHomePage(scope.row)"
          >
            {{ scope.row.name }}
          </el-button>
        </template>
      </el-table-column>

      <el-table-column label="状态" prop="todo"></el-table-column>

      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" link>详情</el-button>
          <el-button
            type="primary"
            link
            @click="handleClickItemCerts(scope.row)"
            >证书</el-button
          >
          <el-button type="primary" link>编辑</el-button>
          <el-button type="danger" link>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "domains-table",

  computed: {
    items() {
      return this.$store.getters["domains/items"];
    },
  },

  methods: {
    getHomePageURL(row) {
      let dn = row.name;
      return "https://" + dn + "/";
    },

    handleClickItemCerts(row) {
      let dn = row.name;
      let path = "/domains/" + dn + "/certs";
      let location = this.$router.resolve({ path });
      // console.log("open " + location.href);
      let url = location.href;
      window.open(url, "_blank");
    },

    handleClickWebHomePage(row) {
      let dn = row.name;
      let url = "https://" + dn + "/";
      window.open(url, "_blank");
    },
  },
};
</script>
